-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development/websocket #1796
base: master
Are you sure you want to change the base?
Development/websocket #1796
Conversation
…m item - Rename 'WEBSERVER' to 'WEBSERVICE' as both client and server utilize state information - Unsollicited 'Pong' may act as a heart beat
…ructure are not yet contructed, and, improve SSL read and write use - SSL read and write methods should only be used if the handshake is successfull - Do not return error values for SSL read and write methods as number of read or written bytes
…en opened but context has not been contructed.
…arily) propagate to SSL structure after construction. - Context should exist - Options should be set
…n 'Handler::Initialize'
…ocket/WebSocketLink] : cherry pick from 'master'
Context settings do not (necessarily) propagate to the SSL structure
…SL read and write Only read or written bytes have values >= 0, otherwise it indicates an error and does not reflect the actual amount
…and sll structure in 'Update'
Source/cryptalgo/SecureSocketPort.h
Outdated
@@ -72,19 +72,26 @@ namespace Crypto { | |||
}; | |||
|
|||
public: | |||
// Type of underlying socket |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enum, together with the enum class context_t split up into server and client do not add any functionality. They are currently used to "determine" the initial state of the _handshaking in the handler but the handler, in the initialize will override the set state, by definition, through the IsOpen() state, which indeed is the only valid way to determine if you are a server, so why all this additional code?
I suggest setting the initial state at ERROR and if during normal runtime you use this state and it is still ERROR, assert where you would not expect it..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good observation. It was not the intended goal to have it overwritten.
Source/cryptalgo/SecureSocketPort.h
Outdated
, _handShaking(CONNECTING) { | ||
} | ||
, _handShaking(type == sockettype_t::CLIENT_SOCKET ? CONNECTING : ACCEPTING) | ||
, _type{type} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the sockettype_t type -> _type is not used anwhere, just drop it, it just confuses..
Source/cryptalgo/SecureSocketPort.h
Outdated
: Core::SocketPort(args...) | ||
, _parent(parent) | ||
, _context(nullptr) | ||
, _ssl(nullptr) | ||
, _callback(nullptr) | ||
, _handShaking(CONNECTING) { | ||
} | ||
, _handShaking(type == sockettype_t::CLIENT_SOCKET ? CONNECTING : ACCEPTING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_handShaking is properly initialized during the Initialize() call t CONNECTING or ACCEPTING, based on the state of the socket if it is being called. Suggest to set it to ERROR here to assert in the INITIALIZE if, for example, it does not have this vale if we "Initialize()". Making sure the Initialize is called only once..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was not the intended goal as mentioned here #1796 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the state of the socket as in open or closed. The intent is to differentiate between and identify the owner of the socket: a server using the accept method to construct it, or, a client that creates it to connect to a server, Handler::ACCEPTING, Handler::CONNECTING respectively.
CLIENT_SOCKET | ||
, SERVER_SOCKET | ||
}; | ||
|
||
Handler(Handler&&) = delete; | ||
Handler(const Handler&) = delete; | ||
Handler& operator=(const Handler&) = delete; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the:
Handler& operator=(Handler&&) = delete;
for upgrading code we should add it now...
Source/cryptalgo/SecureSocketPort.h
Outdated
@@ -107,6 +114,7 @@ namespace Crypto { | |||
|
|||
// Signal a state change, Opened, Closed or Accepted | |||
void StateChange() override { | |||
// ASSERT(_context != nullptr && _ssl != nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that this ASSERT fires... Maybe during the Close Sequence? Please investigate and remove the assert or make sure that under normal conditions it does not fire (IsClosed() == false) || ((_context != nullptr) && (_ssl != nullptr)));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting. In a previous draft PR you did not wanted such solution but promoted the use of ASSERT. Update() already includes a check and ASSERT.
Source/cryptalgo/SecureSocketPort.h
Outdated
@@ -135,17 +143,31 @@ namespace Crypto { | |||
void* _ssl; | |||
IValidator* _callback; | |||
mutable state _handShaking; | |||
const sockettype_t _type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described above, I think we can drop this..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? _handShaking is initially used to identify the server or client side of the connection, but will loose that information once connected or in error.
|
||
uint32_t result = SSL_write(_ssl, buffer, length); | ||
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<time_t>::max()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Operands don't affect result
"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".
Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT
if (_handShaking != OPEN) { | ||
Update(); | ||
} | ||
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<suseconds_t>::max()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Operands don't affect result
"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".
Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT
ad058f5
to
1e7c32b
Compare
using common_time_t VARIABLE_IS_NOT_USED = std::common_type<time_t, uint32_t>::type; | ||
using common_seconds_t VARIABLE_IS_NOT_USED = std::common_type<suseconds_t, uint32_t>::type; | ||
|
||
ASSERT(static_cast<common_time_t>(std::numeric_limits<time_t>::max()) >= static_cast<common_time_t>(waitTime)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Operands don't affect result
"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical operand of "!".
Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT
using common_seconds_t VARIABLE_IS_NOT_USED = std::common_type<suseconds_t, uint32_t>::type; | ||
|
||
ASSERT(static_cast<common_time_t>(std::numeric_limits<time_t>::max()) >= static_cast<common_time_t>(waitTime)); | ||
ASSERT(static_cast<common_time_t>(std::numeric_limits<suseconds_t>::max()) >= static_cast<common_time_t>(waitTime)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Operands don't affect result
"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical operand of "!".
Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT
150d47d
to
8d44d48
Compare
if (_handShaking != OPEN) { | ||
Update(); | ||
} | ||
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<suseconds_t>::max()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Operands don't affect result
"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".
Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT
20cea57
to
52f07c9
Compare
|
||
uint32_t result = SSL_write(_ssl, buffer, length); | ||
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<time_t>::max()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Operands don't affect result
"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".
Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT
if (_handShaking != OPEN) { | ||
Update(); | ||
} | ||
ASSERT( !IsNarrowing(std::numeric_limits<uint32_t>::max(), std::numeric_limits<suseconds_t>::max()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Operands don't affect result
"9223372036854775807L /* static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(std::numeric_limits::max()) */ >= static_cast<Thunder::Crypto::SecureSocketPort::Handler::Open(unsigned int)::common_time_t>(waitTime)" is always true regardless of the values of its operands. This occurs as the logical second operand of "&&".
Medium Impact, CWE-569
CONSTANT_EXPRESSION_RESULT
* [Tests] : Reduce compiler warnings * [Tests/unit/core] : amend '0badc'
52f07c9
to
2f2be2d
Compare
…te' to 'CertificateStore'
… (compile-time) between 'client' and 'server' type sockets Compile-time differentiation allows for use case available signatures
return 0; // 0 - Failurre, 1 - OK | ||
} | ||
|
||
template <typename TYPE = std::false_type> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Parse recovery warning
a default template argument cannot be specified on the definition of a member of a class template outside the template
Low Impact, CWE-none
RW.DEFAULT_ARG_ON_MEMBER_DECL
No description provided.